//
//  LKDayInformationViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/4/19.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKDayInformationViewController.h"
#import "LKDayInformationCell.h"
#import "LKDayInformationDetailViewController.h"
#import "LKWebViewController.h"
@interface LKDayInformationViewController ()<UITableViewDelegate,UITableViewDataSource>


@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)NSMutableArray *dataArray;


@end

@implementation LKDayInformationViewController

-(LKBaseTableview *)tableview{
    if (!_tableview) {
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStylePlain registercellClasss:@[@"LKDayInformationCell"]];
        [self.view addSubview:_tableview];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.emptyDataSetDelegate = self;
        _tableview.emptyDataSetSource = self;
        _tableview.estimatedRowHeight = 200;
    }
    return _tableview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"每日资讯";
    [self getInformationData];
    [self.tableview reloadData];
    // Do any additional setup after loading the view.
}

#pragma mark -tableview的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKDayInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKDayInformationCell"];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    LKWebViewController *vc = [[LKWebViewController alloc] init];
    LKDayInformationModel *model = self.dataArray[indexPath.row];
    vc.url = model.shareurl;
    vc.shareTitle = model.informationTitle;
    vc.shareContent = model.informationContent;
    vc.shareUrl = model.sharingLinks;
    vc.shareIconUrl = model.informationImage;
    vc.showClose = YES;
    [self.navigationController pushViewController:vc animated:YES];
//    LKUserInfor *user = [LKUserInforTool account];
//    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:@"Id",model.Id,@"UserSerialNumber",user.userSerialNumber, nil];
//    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:dayInformationDetailUrl header:[LKUserInforTool header] parameters:param progress:^(NSProgress * _Nullable progress) {
//
//    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
////        NSString *url = [NSString stringWithFormat:@"http://%@",responseObject[@"result"]];
//        vc.url = responseObject[@"result"];
//        vc.showClose = YES;
//        [self.navigationController pushViewController:vc animated:YES];
//    } failure:^(NSString * _Nullable errorMessage) {
//
//    }];
//    vc.url = @"http://www.baidu.com";

//    LKDayInformationDetailViewController *vc = [[LKDayInformationDetailViewController alloc] init];
//    vc.Id =  model.Id;
//    vc.title = model.informationTitle;

}

-(void)getInformationData{
    
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:dayinforlistUrl header:[LKUserInforTool header] parameters:nil progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSArray *arra = responseObject[@"result"];
        for (NSDictionary *dic in arra) {
            LKDayInformationModel *model = [LKDayInformationModel modelWithDictionary:dic];
            [self.dataArray addObject:model];
        }
        [self.tableview reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
